#!/usr/bin/env bash

if [ "$#" -ne "3" ] ; then echo "Syntax: set-version-recursor VERSION DEB_VERSION RPM_VERSION"; exit ; fi

VERSION=$1
DEB_VERSION=$2
RPM_VERSION=$3
[ -z "$VERSION" -o -z "$DEB_VERSION" -o -z "$RPM_VERSION" ] && exit 1

DIST_HOST="$(id -u -n)@$(hostname -f 2>/dev/null || hostname 2>/dev/null || echo localhost)"

sed -r "s/^VERSION=(.*)/VERSION=$VERSION/" -i pdns/dist-recursor
sed -r "s/^DIST_HOST=(.*)/DIST_HOST=$DIST_HOST/" -i pdns/dist-recursor
sed -r "s/Version: (.*)/Version: $RPM_VERSION/" -i pdns/pdns-recursor.spec

sed -r "s/#VERSION#/$VERSION/" -i build-scripts/redhat/pdns-recursor-test.spec
